#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
	int ret, fd;
	char val, buf[2];
	if (argc != 3 || (atoi(argv[2])) != 0 || (atoi(argv[2])) != 1 ) {
		printf ("usage:\n");
		printf ("		./app /dev/led_gpio5_0 <val>\n");
		printf ("		<val>: 0/1\n");
	}

	fd = open (argv[1], O_RDWR);
	if (fd < 0) {
		perror ("open");
		exit (-1);
	}
	printf ("open successed!\n");

	ret = read (fd, &buf[0], 1);
	if (ret >= 0) {
		printf ("read gpio5_0 val %d\n", buf[0]);
	} else {
		perror ("read");
		exit (-1);
	}

	val = atoi (argv[2]);
	printf ("write gpio5_0 val %d\n", val);
	ret = write (fd, &val, 1);
	if (ret == -1) {
		perror ("write");
		close (fd);
		exit (-1);
	}

	close (fd);
	return 0;
}
